home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / ivtestdi.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  6.7 KB  |  250 lines

  1. unit IvTestDi;
  2.  
  3. {$I IVMULTI.INC}
  4.  
  5. { This is a sample dictionary component that contains three languages:
  6.   1) Native
  7.   2) Translated test
  8.   3) Native test
  9.  
  10.   Use this dictionary to test your application. You do not have any kind of
  11.   dictionary data but the test dictionary gererates the translation on
  12.   run time by uppercasing the native string. }
  13.  
  14. interface
  15.  
  16. uses
  17. {$IFDEF WIN32}
  18.   Windows,
  19. {$ELSE}
  20.   WinTypes, WinProcs,
  21. {$ENDIF}
  22.   Classes,
  23.   IvDictio, IvTests;
  24.  
  25. type
  26.   TIvTestDictionary = class(TIvDictionary)
  27.   protected
  28.     FTest: TIvTest;
  29.     FTestType: TIvTestType;
  30.     FReplaceChar: Char;
  31.     FReductionChar: String;
  32.     FSingleByteOptions: TIvSinglebyteTestOptions;
  33.     FUseDoubleByteChars: Boolean;
  34.     FFrom1To5: Integer;
  35.     FFrom6To10: Integer;
  36.     FFrom11To20: Integer;
  37.     FFrom21To30: Integer;
  38.     FFrom31To50: Integer;
  39.     FOver50: Integer;
  40.     FExpandChar: Char;
  41.     FLastChar: Char;
  42.     FTestPrimary: Integer;
  43.  
  44.     function GetLanguageCount: Integer; override;
  45.     procedure GetLanguageData(index: Integer; language: TIvLanguage); override;
  46.     function GetLocaleCount: Integer; override;
  47.     procedure GetLocaleData(index: Integer; locale: TIvLocale); override;
  48.  
  49.     procedure Loaded; override;
  50.     procedure Init;
  51.  
  52.     function GetTestPrimary: Integer;
  53.     function GetTestLangId: Integer;
  54.     function GetTestCodePage: Integer;
  55.  
  56.   public
  57.     constructor Create(owner: TComponent); override;
  58.     destructor Destroy; override;
  59.  
  60.     function TranslateString(
  61.       const str: String;
  62.       var translation: String): Boolean; override;
  63.     function TranslateContextString(
  64.       const str, form, component: String;
  65.       var translation: String): Boolean; override;
  66.  
  67.   published
  68.     property TestType: TIvTestType read FTestType write FTestType default ivttCodePage;
  69.     property TestPrimary: Integer read FTestPrimary write FTestPrimary default 0;
  70.     property ReplaceChar: Char read FReplaceChar write FReplaceChar default REPLACE_CHAR_C;
  71.     property ReductionChar: String read FReductionChar write FReductionChar;
  72.     property SingleByteOptions: TIvSinglebyteTestOptions read FSingleByteOptions write FSingleByteOptions
  73.       default [ivstUpperCase];
  74.     property From1To5: Integer read FFrom1To5 write FFrom1To5 default FROM_1_TO_5_C;
  75.     property From6To10: Integer read FFrom6To10 write FFrom6To10 default FROM_6_TO_10_C;
  76.     property From11To20: Integer read FFrom11To20 write FFrom11To20 default FROM_11_TO_20_C;
  77.     property From21To30: Integer read FFrom21To30 write FFrom21To30 default FROM_21_TO_30_C;
  78.     property From31To50: Integer read FFrom31To50 write FFrom31To50 default FROM_31_TO_50_C;
  79.     property Over50: Integer read FOver50 write FOver50 default OVER_50_C;
  80.     property ExpandChar: Char read FExpandChar write FExpandChar default EXPAND_CHAR_C;
  81.     property LastChar: Char read FLastChar write FLastChar default LAST_EXPAND_CHAR_C;
  82.     property UseDoubleByteChars: Boolean read FUseDoubleByteChars write FUseDoubleByteChars default True;
  83.   end;
  84.  
  85. implementation
  86.  
  87. uses
  88.   SysUtils;
  89.  
  90. constructor TIvTestDictionary.Create(owner: TComponent);
  91. begin
  92.   inherited Create(owner);
  93.   FTestType := ivttCodePage;
  94.   FTestPrimary := 0;
  95.   FSingleByteOptions := [ivstUpperCase];
  96.   FUseDoubleByteChars := True;
  97.   FFrom1To5 := FROM_1_TO_5_C;
  98.   FFrom6To10 := FROM_6_TO_10_C;
  99.   FFrom11To20 := FROM_11_TO_20_C;
  100.   FFrom21To30 := FROM_21_TO_30_C;
  101.   FFrom31To50 := FROM_31_TO_50_C;
  102.   FOver50 := OVER_50_C;
  103.   FExpandChar := EXPAND_CHAR_C;
  104.   FLastChar := LAST_EXPAND_CHAR_C;
  105.   FReplaceChar := REPLACE_CHAR_C;
  106.   FReductionChar := '';
  107. end;
  108.  
  109. destructor TIvTestDictionary.Destroy;
  110. begin
  111.   FTest.Free;
  112.   inherited Destroy;
  113. end;
  114.  
  115. procedure TIvTestDictionary.Loaded;
  116. begin
  117.   if not (csDesigning in ComponentState) then
  118.     Init;
  119. end;
  120.  
  121. procedure TIvTestDictionary.Init;
  122. begin
  123.   if FTest <> nil then
  124.     Exit;
  125.  
  126.   case FTestType of
  127.     ivttCover:
  128.       FTest := TIvCoverTest.CreateValue(ReplaceChar);
  129.  
  130.     ivttMinimum:
  131.       FTest := TIvMinimumTest.CreateValue(ReductionChar);
  132.  
  133.     ivttCodePage:
  134.       case IvGetCharacterSetType(IvMakeLangId(GetTestPrimary, SUBLANG_NEUTRAL)) of
  135.         ivcsSingleByte:
  136.           FTest := TIvSingleByteTest.CreateValue(GetTestCodePage, FSingleByteOptions);
  137.  
  138.         ivcsMultiByte:
  139.           FTest := TIvMultibyteTest.CreateValue(GetTestCodePage, FUseDoubleByteChars);
  140.  
  141.         ivcsBiDirectional:
  142.           FTest := TIvBidirectionalTest.CreateValue(GetTestCodePage);
  143.       end;
  144.   end;
  145. end;
  146.  
  147. function TIvTestDictionary.GetTestPrimary: Integer;
  148. begin
  149.   if FTestPrimary <> 0 then
  150.     Result := FTestPrimary
  151.   else
  152.   begin
  153. {$IFDEF WIN32}
  154.     Result := IvGetPrimaryFromLocale(GetUserDefaultLCID);
  155.     if Result = LANG_ENGLISH then
  156.       Result := LANG_FINNISH;
  157. {$ELSE}
  158.     Result := LANG_FINNISH;
  159. {$ENDIF}
  160.   end;
  161. end;
  162.  
  163. function TIvTestDictionary.GetTestLangId: Integer;
  164. begin
  165.   Result := IvMakeLangId(GetTestPrimary, SUBLANG_NEUTRAL);
  166. end;
  167.  
  168. function TIvTestDictionary.GetTestCodePage: Integer;
  169. begin
  170.   Result := IvLangIdToCodePage(GetTestLangId);
  171. end;
  172.  
  173. function TIvTestDictionary.GetLanguageCount: Integer;
  174. begin
  175.   Result := 3;
  176. end;
  177.  
  178. procedure TIvTestDictionary.GetLanguageData(index: Integer; language: TIvLanguage);
  179. begin
  180.   { This dictionary supports English and Finnish }
  181.  
  182.   language.EnglishName := '';
  183.   language.NativeName := '';
  184.  
  185.   case index of
  186.     0:
  187.     begin
  188.       language.Primary := LANG_NEUTRAL;
  189.       language.Options := [ivloPureASCII];
  190.       language.Init;
  191. {$IFNDEF WIN32}
  192.       language.EnglishName := 'Native';
  193.       language.NativeName := 'Native';
  194. {$ENDIF}
  195.     end;
  196.  
  197.     1:
  198.     begin
  199.       language.Primary := GetTestPrimary;
  200.       language.Init;
  201.       language.EnglishName := language.EnglishName + ' (Translated)';
  202. {$IFNDEF WIN32}
  203.       language.NativeName := 'Translated test';
  204. {$ENDIF}
  205.     end;
  206.  
  207.     2:
  208.     begin
  209.       language.Primary := GetTestPrimary;
  210.       language.Init;
  211.       language.EnglishName := language.EnglishName + ' (Native)';
  212. {$IFNDEF WIN32}
  213.       language.NativeName := 'Native test';
  214. {$ENDIF}
  215.     end;
  216.   end;
  217. end;
  218.  
  219. function TIvTestDictionary.GetLocaleCount: Integer;
  220. begin
  221.   Result := 0;
  222. end;
  223.  
  224. procedure TIvTestDictionary.GetLocaleData(index: Integer; locale: TIvLocale);
  225. begin
  226. end;
  227.  
  228. function TIvTestDictionary.TranslateString(
  229.   const str: String;
  230.   var translation: String): Boolean;
  231. begin
  232.   if (ActiveLanguage = 1) and (str <> '-') then
  233.   begin
  234.     Init;
  235.     translation := FTest.Translate(str);
  236.   end
  237.   else
  238.     translation := str;
  239.   Result := True;
  240. end;
  241.  
  242. function TIvTestDictionary.TranslateContextString(
  243.   const str, form, component: String;
  244.   var translation: String): Boolean;
  245. begin
  246.   Result := TranslateString(str, translation);
  247. end;
  248.  
  249. end.
  250.